<?php

namespace App\model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Salary extends Model
{
    /*
    *@content 工资明细
    *@author *****
    */

    protected $table = 'salary';
    protected $primaryKey='s_id';
    public $timestamps = false;
    protected $fillable = array('use_id', 's_actual', 's_state');


    /*
	*获取工资明细
	*@author *****
    */
    public function getData($id){
        return $this->where('s_id',$id)->get()->toArray();
    }
    /**
     * 员工薪资插入
     * 作者：*****
     */
    public function insertSalary($arr){
        foreach ($arr as $key => $value) {
            $ar = $this->where('use_id', '=', $value['use_id'])->first();
            if (empty($ar)) {
                $this->insert([
                    ['use_id' => $value['use_id'], 's_actual' => $value['wag_basic'] + $value['wag_bonus'] + $value['wag_atten'] + $value['wag_subsidy'] - $value['kouquanqin'] - $value['kouqingjia'] - $value['koubuzhu'] - 60, 's_state' => 0],
                ]);
            }
        }
        return $this->get();
    }
    /**
     * 修改员工薪资状态
     */
    public function editState($use_id){
            $this
            ->where('use_id',$use_id)
            ->update(array('s_state' => 1));
    }
    /**
     * 收入页面员工薪资支出查询
     * 作者：*****
     */
    public function income(){
        return $this->sum('s_actual');
    }


    

}
